//移动数组元素，使得所有偶数在奇数的前面
#include <iostream>
#include <vector>

void ReorderOddEven(std::vector<int>& num, bool (*func)(int))
{
    if(num.size() <= 1)
        return;

    int left = 0;
    int right = num.size() - 1;

    while(left < right)
    {
        //从后往前找一个偶数
        while(left < right && func(num[right]) != 0)
            right--;
        //从前往后找一个奇数
        while(left < right && func(num[left]) == 0)
            left++;
        //如果相遇了就没必要交换了
        if(left < right)
            std::swap(num[left], num[right]);
    }
}

bool Func(int number)
{
    return number & 0x1;
}

int main()
{
    std::vector<int> num = {1,2,5,3,2,6,7,4};
    ReorderOddEven(num, Func);
    
    for(auto n : num)
    {
        std::cout << n << " ";
    }
    std::cout << std::endl;
    return 0;
}